<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>我的-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
			<a href="<%=basePath %>/xs/my/studentInfo?sid=${user.parent.studentId}" id="input_head">
				<div style="position: absolute;background: #78ca6a;width: 100%;padding: 5px 10px;">
						<span><img src="<%=basePath %>/images/tips.png"></span>
						<span class="f-white">学生学籍信息采集</span>
				</div>
			</a>
			<div class="wd_hd weui_cells_access">
				<a class="weui_cell" href="javascript:;">
	                <div class="weui_cell_hd"><img src="${config.imgUrl }/${user.parent.headImgUrl}" class="touxiang circle bg-blue-b"></div>
	                <div class="weui_cell_bd weui_cell_primary" style="text-align: left;padding-left: 10px;">
	                    <p class="f-green"><b>${user.parent.name } 家长</b></p>
						<p onclick="relationShow()">关系：<span id="relation" class="f-green">${user.parent.relation }</span> <i class="icon icon-67 f20 f-blue"></i></p>
	                	<p class="f-green">${user.parent.studentName }</p>
	                	<p>${user.parent.gradeName }（${user.parent.clazz }）班</p>
	                </div>
	                <img src="<%=basePath %>/images/ewm.png" class="share_ewm" style="width:30px;display:block">
	                <div class="weui_cell_ft share_ewm"></div>
	            </a>
			</div>
			
			<div class="czjl-top-list clearfix" style="background: #fff;">
	        	<ul>
	        		<c:forEach var="itm" items="${list }">
	        			<a href="<%=basePath%>/xs/my?sid=${itm.id}">
		        			<li>
			        			<img src="<%=basePath%>/images/default.jpg">
			        			<span>${itm.name }</span>
			        		</li>
	        			</a>
	        		</c:forEach>
	        		<li class="yaoqing tianjia" onclick="addStudent()">
	        			<img style="border-radius: 0;" src="<%=basePath%>/images/tianjia@3x.png">
	        			<span>添加</span>
	        		</li>
	        	</ul>
	        </div>
			<div class="weui_cells weui_cells_access mt0" id="studentInfo">
				<a class="weui_cell" href="<%=basePath%>/xs/my/studentInfo?sid=${user.parent.studentId}">
					<div class="weui_cell_hd">
	                	<img alt="" style="width:20px;margin-right:10px;display:block" src="<%=basePath%>/images/wode_dianji@3x.png">
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>学生信息采集</p>
	                </div>
	                <div class="weui_cell_ft"></div>
	            </a>
	            <a class="weui_cell" href="<%=basePath%>/xs/student/unbind?sid=${user.parent.studentId}">
					<div class="weui_cell_hd">
	                	<img alt="" style="width:20px;margin-right:10px;display:block" src="<%=basePath%>/images/wode_dianji@3x.png">
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>解绑学生</p>
	                </div>
	                <div class="weui_cell_ft"></div>
	            </a>
			</div>
			
			<div class="weui_cells weui_cells_access">
				<c:forEach items="${user.resourceList}" var="itm" begin="10" varStatus="status">
					<c:if test="${(status.count-1)%3 == 0 && status.count > 1}">
						</div>
						<div class="weui_cells weui_cells_access" style="margin: 10;">
					</c:if>
			            <a class="weui_cell" href="<c:choose><c:when test='${itm.isExtLink == "N" }'><%=basePath%>${user.currUrl}${itm.resourceUrlValue}&sid=${user.parent.studentId }</c:when><c:otherwise>${itm.resourceUrlValue}&openid=${user.openid }&sid=${user.parent.studentId }</c:otherwise></c:choose>">
			                <div class="weui_cell_hd">
			                		<img alt="" style="width:20px;margin-right:10px;display:block" src="<%=basePath %>/images/${itm.icon}">
			                </div>
			                <div class="weui_cell_bd weui_cell_primary">
			                    <p>${itm.resourceName }</p>
			                </div>
			                <div class="weui_cell_ft"></div>
			            </a>
		        </c:forEach>
	        </div>
		</div>
	</div>
	<div style="display:none;" id="weui_mask" class="weui_mask weui_mask_visible" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);"></div>
	<div id="stuBind" class="stu-bind">
		<div class="head">
			<p style="text-align: center;">微信扫一扫 码上绑定${user.parent.studentName }</p>
		</div>
		<div id="qrCodeImg" class="middle">
		</div>
		<div class="footer">
			<p>请妥善保管好二维码，不要让陌生人扫描噢！</p>
		</div>
	</div>
	<c:if test="${user.parent.relation == null }">
		<div id="shareStu" class="guide_box"><img class="invest_box" src="<%=basePath %>/images/yindao_fenxiang.png"/></div>
		<div id="addStu" class="guide_box hide"><img class="add_box" src="<%=basePath %>/images/yindao_tianjia.png"/></div>
	</c:if>
	<div id="relation_box" class="hide">
		<div class="relation_head"><img style="width: 100%;" src="<%=basePath %>/images/success_relation.png"/></div>
		<div class="weui_cells" style="width: 90%;left: 5%;border-top: 1px solid #f1e8e8;margin-top: -8px;">
            <div class="weui_cell">
                <div class="weui_cell_hd pr20">关系</div>
                <div class="weui_cell_bd weui_cell_primary">
                	<ul>
	                	<li class="list-del">爸爸</li>
	                	<li class="list-del">妈妈</li>
	                	<li class="list-del">叔叔</li>
	                	<li class="list-del">阿姨</li>
	                	<li class="list-del">爷爷</li>
	                	<li class="list-del">奶奶</li>
	                	<li class="list-del">其它</li>
					</ul>
                </div>
            </div>
            <c:if test="${user.parent.phone == null}">
	            <div class="weui_cell">
	                <div class="weui_cell_hd pr20">电话</div>
	                <div class="weui_cell_bd weui_cell_primary">
	                	<input type="text" value="" class="input_box" id="phone"/>
	                </div>
	            </div>
	            <p class="f-13 f-red ml20">请填写您的联系方式，方便老师联系到您,谢谢您的支持！</p>
	        </c:if>
            <div class="weui_cell" style="border-top: 1px solid #f1e8e8;">
            	<p class="button_box" onclick="updateRelation()">确定</p>
            </div>
        </div>
	</div>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script>
	$(function() {
		init();
		$(".invest_box").click(function() {
			$("#shareStu").remove();
			$("#addStu").removeClass("hide");
		})
		$(".add_box").click(function() {
			$("#addStu").remove();
			$("#weui_mask").addClass("no_close").show();
			$("#relation_box").show();
		})
		$(".list-del").click(function() {
			$(this).addClass("active").siblings().removeClass("active");
		})
		$(".handing").click(function() {
			alert("谢谢关注，功能正在完善中...")
		});
		$("#weui_mask").click(function() {
			if($(this).hasClass("no_close")){
				return;
			}
			$("#weui_mask").hide();
			$("#stuBind").hide();
			$("#relation_box").hide();
		});
		$(".share_ewm").click(function() {
			$("#weui_mask").addClass("weui_mask_visible").show();
			$("#stuBind").show();
			var inviteEwm = "${user.parent.inviteEwm}";
			var ewmInvalidTime = new Date("${user.parent.ewmInvalidTime}").getTime()
			if(inviteEwm.length > 0 && parseFloat(ewmInvalidTime) > (new Date().getTime())) {
				$("#qrCodeImg").html('<img src="'+inviteEwm+'">');
			}else {
				$.ajax({
		         	url : basePath + "/xs/my/getInviteEwm",
		 	 		type : "post",
		 	 		dataType : "json",
		            success: function(data){
		            	if(data.code == '000') {
		            		$("#qrCodeImg").html('<img src="'+data.data+'">');
		            	}
		             },
		             error: function(xhr, type){
		                 
		             }
		         });
			}
		});
	});
	function relationShow() {
		$("#weui_mask").addClass("weui_mask_visible").show();
		$("#relation_box").show();
	}
	function addStudent(){
		var redirectUrl = window.location.href;
		window.location.href = basePath + "/student/bind?sid=${user.parent.studentId}&redirectUrl=" + redirectUrl;
	}
	function updateRelation() {
		var relation = $(".list-del.active").html();
		if(!relation) {
			alert("请选择与小孩关系");
			return;
		}
		var phone = $("#phone").val();
		if(phone != null && phone == '') {
			alert("请填写您的联系电话");
			return;
		}
		$.ajax({
         	url : basePath + "/xs/my/infoUpdate",
 	 		type : "post",
 	 		dataType : "json",
 	 		data : {
 	 			relation: relation,
 	 			phone: $("#phone").val()
 	 		},
            success: function(data){
            	if(data.code == '000') {
            		$("#relation").html(relation);
            		$("#weui_mask").removeClass("no_close").hide();
            		$("#relation_box").hide();
            		$.alert("设置成功！", "");
            	}
             },
             error: function(xhr, type){
                 
             }
        });
	}
	function init() {
		var inputTime = "${student.infoInputTime}";
		if(inputTime.length == 0) {
			$("#studentInfo").show();
			$("#input_head").show();
		}else {
			var infoInputTime = new Date(inputTime);
			if(addDay(infoInputTime, 1).getTime() > new Date().getTime()) {
				$("#studentInfo").show();
			}
		}
	}
</script>
</body>
</html>